#include "coid/svc/coidsvc.h"

//{client 
#include "coid/comm/binstream/stlstream.h"
//}client

#include "string.h"


//{client 
struct birth_date
{
	int day;
	int month;
	int year;

	friend binstream & operator << ( binstream & out, const birth_date & x ) 	
	{ 
		return out << x.day << x.month << x.year; 
	};

    friend binstream & operator >> ( binstream & in, birth_date & x ) 
	{
		return in >> x.day >> x.month >> x.year;      /// notice the FIFO order (first in, first out)
    };

	friend metastream& operator << ( metastream& m, const birth_date & x )
    {
        MSTRUCT_OPEN(m,"birth_date");
		MM(m,"day",x.day);
		MM(m,"month",x.month);
		MM(m,"year",x.year);
		MSTRUCT_CLOSE(m);
    }
};
//}client

//{client 
struct login_inf
{
	std::string login_name;
	std::string password;
	std::string retype_password;

	friend binstream & operator << ( binstream & out, const login_inf & x ) 	
	{ 
		return out << x.login_name << x.password << x.retype_password; 
	};

    friend binstream & operator >> ( binstream & in, login_inf & x ) 
	{
		return in >> x.login_name >> x.password >> x.retype_password;      /// notice the FIFO order (first in, first out)
    };

	friend metastream& operator << ( metastream& m, const login_inf & x )
    {
        MSTRUCT_OPEN(m,"login_inf");
		MM(m,"login_name",x.login_name);
		MM(m,"password",x.password);
		MM(m,"retype_password",x.retype_password);
		MSTRUCT_CLOSE(m);
    }

};
//}client 

//{client 
struct address_struct
{
	std::string street;
	std::string	city;
	std::string state;
	std::string zip;

	friend binstream & operator << ( binstream & out, const address_struct & x ) 	
	{ 
		return out << x.street << x.city << x.state << x.zip; 
	};

    friend binstream & operator >> ( binstream & in, address_struct & x ) 
	{
		return in >> x.street >> x.city >> x.state >> x.zip;      /// notice the FIFO order (first in, first out)
    };

	friend metastream& operator << ( metastream& m, const address_struct & x )
    {
        MSTRUCT_OPEN(m,"address");
		MM(m,"street",x.street);
		MM(m,"city",x.city);
		MM(m,"state",x.state);
		MM(m,"zip",x.zip);
		MSTRUCT_CLOSE(m);
    }

};
//}client


//{client 
struct person
{
	std::string title;
	std::string name;
	std::string surname;
	address_struct address;
	login_inf login_information;
	birth_date birth_information;

	friend binstream & operator << ( binstream & out, const person & x ) 	
	{ 
		return out << x.title << x.name << x.surname << x.address << x.login_information << x.birth_information; 
	};

    friend binstream & operator >> ( binstream & in, person & x ) 
	{
		return in >> x.title  >> x.name >> x.surname >> x.address >> x.login_information >> x.birth_information;      /// notice the FIFO order (first in, first out)
    };

    friend metastream& operator << ( metastream& m, const person & x )
    {
        MSTRUCT_OPEN(m,"person");
		MM(m,"title",x.title);
		MM(m,"name",x.name);
		MM(m,"surname",x.surname);
		MM(m,"address",x.address);
		MM(m,"login_inforamtion",x.login_information);
		MM(m,"birth_information",x.birth_information);
        MSTRUCT_CLOSE(m);
    }

};
//}client


class ClientDatabase
{
	int status;

public:
	ClientDatabase()
	{	
	}

	net_fnc_s net_meta opcd accept_connect(net_in std::vector< birth_date > & birt_d);

	// sets personal data
	net_fnc net_meta opcd add_user( net_in person & person_in );


	net_fnc net_meta opcd set_address( net_in address_struct & address_in );

};